import axios from 'axios';
import type { RouteRecordNormalized } from 'vue-router';
import { UserState } from '@/store/modules/user/types';

export interface LoginData {
  username: string;
  password: string;
}


export interface SmsCode {
  username: string;
  password: string;
}

export interface LoginRes {
  organization: any;
  userinfo: any;
  token: string;
  code: number,
  msg: string,
  time: number,
  data: any
}


export interface SmsCodeRes{
  code: number,
  msg?: string,
  time: number,
  data: any
}



/**
 * 用户登录
 * @param data 
 * @returns 
 */
export function login(data: LoginData) {
  return axios.post<LoginRes>('/organization/auth/login', data);
}

/**
 * 获取短信验证码
 * @param data 
 * @returns 
 */
export function getSmsCode(data: SmsCode) {
  return axios.post<SmsCodeRes>('/organization/auth/getSmsCode', data);
}


/**
 * 用户退出登录
 * @returns 
 */
export function logout() {
  return axios.post<LoginRes>('/organization/auth/logout');
}

/**
 * 获取用户信息
 * @returns 
 */
export function getUserInfo() {
  return axios.post<UserState>('/api/user/info');
}

/**
 * 获取菜单列表
 * @returns 
 */
export function getMenuList() {
  return axios.post<RouteRecordNormalized[]>('/api/user/menu');
}
